{extend name='public/base' /}

{block name='content'}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15="">
                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">当前密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="oldPassword" lay-verify="required" lay-vertype="tips"
                                       class="layui-input" lay-reqText="请输入旧密码">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" lay-verify="pass" lay-vertype="tips"
                                       autocomplete="off" id="LAY_password" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="repassword" lay-verify="repass" lay-vertype="tips"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="formInfo">确认修改</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name='js'}
<script>
    layui.use(['upload', 'form', 'layer'], function () {
        let $ = layui.jquery,
            form = layui.form;
        form.on('submit(formInfo)', function (data) {
            $.ajax({
                type: "post",
                url: '/manage/system/myPassword/update',
                data: data.field,
                success: function (data) {
                    // 根据服务端二次验证的结果进行跳转等操作
                    if (data.code !== 0) {
                        layer.msg(data.message, {icon: 5});
                    } else {
                        layer.msg('修改成功', {icon: 1});
                        $('.layui-input').val('');
                    }
                }
            });
            return false;
        });
        //表单验证规则
        form.verify({
            // username: function(value, item){ //value：表单的值、item：表单的DOM对象
            //     if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
            //         return '用户名不能有特殊字符';
            //     }
            //     if(/(^\_)|(\__)|(\_+$)/.test(value)){
            //         return '用户名首尾不能出现下划线\'_\'';
            //     }
            //     if(/^\d+\d+\d$/.test(value)){
            //         return '用户名不能全为数字';
            //     }
            // }
            repass: function (value, item) {
                let pass = $('#LAY_password').val();
                if (pass !== value) {
                    return '两次输入的密码不一致';
                }
            },

            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            pass: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'],

        });
    });
</script>
{/block}